JavaScript

A5.form.populateSelect Method

Do not use this method to populate a dropdown box in a UX or Grid Component. Use {dialog.object}.populateDropdownBox or {grid.object}.populateDropdownBox instead.

Syntax

A5.form.populateSelect(eleId, curValue, data, clearExistingEntries);

Arguments

eleIdstring

The ID attribute of the select control.

curValuestring

The value to show as selected when the control is populated. If it is specified, the control will not show any "blank" or empty option. If it is not specified (value = ""), a blank option will be shown at the bottom of the list of options.

dataobject array

The list of values used to create the option list.

clearExistingEntriesboolean

A true/false value. If true, it clears any values in the select control on the page before creating the new list. If false, it does not clear the list. In most cases, clearExistingEntries should be set to true.

Description

Populates a dropdown box.

Discussion

Select boxes or dropdowns are common controls on a page. This function allows populating a dropdown with values from a callback page.

There are four required input parameters:

  • eleId
  • curValue
  • data
  • clearExistingEntries

'data' can be an array of single values such as:

['AL','MA','TX','VA']

When the list is created the display value and the saved value will be the same. This would be equivalent to:

< select name="states">
     < option value="AL">AL</option>
    < option  value="MA">MA</option>
    < option  value="TX">TX</option>
    < option  value="VA">VA</option>
</select>

However, it is often desired to show one value, but select another. The saved value may be a state code, but the display may be the full state name. If the an entry in the array is itself an array, then the first value in the array will be the displayed text, and the second will be the returned value. The following array would create the equivalent select options listed below:

[['Alabama','AL'],['Massachusetts','MA'],['Texas','TX'],['Virginia','VA']]

< select  name="states">
    < option value="AL">Alabama< /option>
     < option value="MA">Massachusetts< /option>
    < option  value="TX">Texas< /option>
    < option  value="VA">Virginia< /option>
< /select>

The full code to set a SELECT with an ID of "Bill_State" to a VALUE of "MA" using the list of states above, and removing any old entries from the SELECT would be:

A5.form.populateSelect('Bill_State','MA',[['Alabama','AL'],['Massachusetts','MA'],</br>['Texas','TX'],['Virginia','VA']],true);